<?php
function_exists('UnixPath')  || die('OK');

	$ACT = array('list', 'add', 'aok', 'edit', 'eok', 'del', 'form'); //', 'create', 'cok' , bind', 'bok',
	in_array($_GET['act'], $ACT) || $_GET['act'] = 'list';
	//$html['tpl_right_act'] = $_GET['act'];

	$_GET['pid']	= (int) $_GET['pid'];
	$_GET['id']	= (int) $_GET['id'];

	$P = E::$DB->one('_table_list', 'id='.$_GET['pid']);
	$P['id'] || A::msg('错误了!');
	$P['ShowInfo']	= @unserialize($P['ShowInfo']);

	$body['navlist'] = array(
		'list' => '分组列表',
		'add' => '添加分组',
	);

	$body['navslist'] = array(
		array('修改表', '?mod='.$_GET['mod'].'&fun=table&act=edit&id='.$P['id']),
		array('更新表单', '?mod='.$_GET['mod'].'&fun=field&act=form&pid='.$P['id']),
		array('字段管理', '?mod='.$_GET['mod'].'&fun=field&act=list&pid='.$P['id']),
	);
	$ShowTypes	= require( B_DIR . '/_res/const/ShowTypes.php');
	$tpl->assign_by_ref('ShowTypes', $ShowTypes);

	$body['_url'] = '&pid='.$P['id'];
	$body['url'] = $html['url'].$body['_url'];
	$body['node_tree'] = '<a href="?mod=_super&fun=table&act=list">数据表列表</a> <small>&#187;</small> '.$P['description'].' <small>&#187;</small>  <a href="'.$body['url'].'&act=list">字段分组</a>'; 

	//E::$DB->_tab = '_table_group';

	$Fields	= E::$DB->ary('_table_field', 'tid=' . $_GET['pid'] .' ORDER BY gid ASC, orderId DESC , id ASC' , 'id, fieldName, gid', 'id' );
	$tpl->assign_by_ref('Fields', $Fields);

	$Groups	= E::$DB->ary('_table_group', 'tid=' . $_GET['pid'] .' ORDER BY iOrder DESC , id ASC' , 'id, name', 'id' );
	$tpl->assign_by_ref('Groups', $Groups);
	
	if( $_GET['act'] === 'list' ){
		$p = E::$DB->page('_table_group', 'tid=' . $_GET['pid'] );
		$L = E::$DB->all('_table_group',  'tid=' . $_GET['pid'] . ' ORDER BY iOrder DESC, id ASC' . $p['limit']);
	}

	if( $_GET['act'] == 'add' ){

	}
	
	if( $_GET['act'] == 'aok' ){
		$_POST['tid'] = $_GET['pid'];
		$id	= E::$DB->insert('_table_group', 'name, iOrder, tid');
		A::msg('添加字段组 '.$_POST['name'].' 完成!', $_POST['jurl'], 1, 1 );
	}

	if( $_GET['act'] == 'edit' ){
		$L	=  E::$DB->one('_table_group', 'id=' . $_GET['id'] );
		if( $L['tid'] != $_GET['pid'] ){
			die('Error on ' . __FILE__ . ' ' . __LINE__ );
		}
	}

	if( $_GET['act'] == 'eok' ){
		$L	=  E::$DB->one('_table_group', 'id=' . $_GET['id'] );
		if( $L['tid'] != $_GET['pid'] ){
			die('Error on ' . __FILE__ . ' ' . __LINE__ );
		}
		E::$DB->update('_table_group', 'name, iOrder', 'id=' . $L['id']);
		A::msg('修改字段组 ' . $_POST['name'] . ' 完成!', $_POST['jurl'], 1, 1 );

	}

